import java.util.StringTokenizer;

class P10443 {

   public static void main(String[] args) {
       try {
       int cases = Integer.parseInt(readLn());
       for (int k = 0; k < cases; k++) {
           StringTokenizer st = new StringTokenizer(readLn());
           int y = Integer.parseInt(st.nextToken());
           int x = Integer.parseInt(st.nextToken());
           int n = Integer.parseInt(st.nextToken());
           char[][] initial = new char[y][x];
           char[][] finish = new char[y][x];
           for (int j = 0; j < y; j++) {
               read(initial[j]);

           }

           for (int i = 0; i < n; i++) {
               // System.out.println(">>");
               // print(initial, x, y);
               // System.out.println();
               // print(finish, x, y);
               // System.out.println("<<");
               finish = new char[y][x];
               process(initial, finish, x, y);
               initial = finish;
           }
           print(finish, x, y);
           // print(initial, x, y);
           if (k + 1 != cases) System.out.println();
       }
       } catch (Exception e) {
           while(true) {

           }
       }
   }

   private static void read(char[] initial) {
       String line = readLn();
       for (int k = 0; k < line.length(); k++) {
           initial[k] = line.charAt(k);
       }
   }

   private static void print(char[][] array, int x, int y) {
       for (int i = 0; i < y; i++) {
           for (int j = 0; j < x; j++) {
               System.out.print(array[i][j]);
           }
           System.out.println();
       }
   }

   private static void process(char[][] grid, char[][] grid1, int x, int y) {
       for (int i = 0; i < y; i++) {
           for (int j = 0; j < x; j++) {
               grid1[i][j] = grid[i][j];
           }
       }

       for (int i = 0; i < y; i++) {
           for (int j = 0; j < x; j++) {
               if (j > 0)
                   if (A_beats_B(grid[i][j], grid[i][j - 1]))
                       grid1[i][j - 1] = grid[i][j];

               if (i > 0)
                   if (A_beats_B(grid[i][j], grid[i - 1][j]))
                       grid1[i - 1][j] = grid[i][j];

               if (j < x - 1)
                   if (A_beats_B(grid[i][j], grid[i][j + 1]))
                       grid1[i][j + 1] = grid[i][j];

               if (i < y - 1)
                   if (A_beats_B(grid[i][j], grid[i + 1][j]))
                       grid1[i + 1][j] = grid[i][j];

           }
       }
       grid = grid1;
   }

   static boolean A_beats_B(char a, char b) {
       return a == 'R' && b == 'S' || a == 'S' && b == 'P' || a == 'P'
               && b == 'R';
   }

   private static char put(char index, char other) {
       switch (index) {
       case 'R':
           if (other == 'R')
               return 0;
           if (other == 'S')
               return 'R';
           if (other == 'P')
               return 0;
       case 'S':
           if (other == 'R')
               return 0;
           if (other == 'S')
               return 0;
           if (other == 'P')
               return 'S';
       case 'P':
           if (other == 'R')
               return 'P';
           if (other == 'S')
               return 0;
           if (other == 'P')
               return 0;
       }
       return index;
   }

   static String readLn() {
       String newLine = System.getProperty("line.separator");
       StringBuffer buffer = new StringBuffer();
       int car = -1;
       try {
           car = System.in.read();
           while ((car > 0) && (car != newLine.charAt(0))) {
               buffer.append((char) car);
               car = System.in.read();
           }
           if (car == newLine.charAt(0))
               System.in.skip(newLine.length() - 1);
       } catch (java.io.IOException e) {
           return (null);
       }
       if ((car < 0) && (buffer.length() == 0))
           return (null);
       return (buffer.toString()).trim();
   }

}